package top.chendawei.main.facade;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.hanyun.oss.service.HanyunLoginUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.chendawei.system.beans.entity.SysUser;
import top.chendawei.system.service.ICommonService;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class LoginUserseviceImpl implements HanyunLoginUserService {
    @Autowired
    private UserFacadeImpl userFacade;
    @Autowired
    private ICommonService commonService;

    @Override
    public Map<String, Object> loginCheck(JSONObject body) {
        log.info("body:{}", body);
        String realName=body.getString("realName");
        String loginName =body.getString("loginName");
        // 登陆后根据token获取用户信息,以下为模拟
        Map<String, Object> data = Maps.newHashMap();
        SysUser dbUser = commonService.commonFind(SysUser.class, 1);
        List<Long> ids = JSONUtil.toList(JSONUtil.parseArray(dbUser.getRoleIds()), Long.class);
        dbUser.setRoleIdList(ids);
        String token = userFacade.getToken(dbUser);
        data.put("token", token);
        data.put("user", dbUser);
        data.put("realName", realName);
        data.put("loginName", loginName);
        return data;
    }
}
